#ifndef CHESSBOTBOARD_CONFIG_H
#define CHESSBOTBOARD_CONFIG_H

#include <WString.h>

#define OTA_OR_SCREEN_KEY 0 // 1: 打开OTA, 0: 打开Screen
#define LOW_POWER_KEY 0     // 1: 打开OTA, 0: 打开Screen

#define DISABLE_WDT

#define FIRMWARE_VERSION "1.0.0"
#define PI2 (PI * 2)
#define IK_PRINT_F1 1

/// For BLE ____________________________________________________________________________________
#define BLE_DEFAULT_NAME "CB-DVT1" // 未设置SN码的默认蓝牙名称

/// For ROBOT ____________________________________________________________________________________
/** 模板

 * */

// #define HBOT_EVT1
// #define HBOT_EVT2_SLIDER
#define HBOT_EVT2_SHAFT

#define NVS_KEY_LAST_X "last_x"
#define NVS_KEY_LAST_Y "last_y"
#define HOMING_OFFSET 10.0f // 归位偏移量
/** 模板
#ifdef HBOT_EVT1
#elif defined(HBOT_EVT2_SLIDER)
#elif defined(HBOT_EVT2_SHAFT)
#endif // HBOT_EVT
 * */

#ifdef HBOT_EVT1
// EVT1 : 一圈对应周长(GT2*模数20）= 40mm，对应3600步
#define HBOT_STEP_DIS ((200 * 16 * 0.5) / 40.0f)
#elif defined(HBOT_EVT2_SLIDER)
// EVT2 M5*20
#define HBOT_STEP_DIS ((200 * 16 * 0.5) / 100.0f)
#elif defined(HBOT_EVT2_SHAFT)
// EVT2 M3*25
// #define HBOT_STEP_DIS ((200 * 16 * 0.5) / 75.0f)
#define HBOT_STEP_DIS ((200 * 8) / 40.0f)

#endif // HBOT_EVT

/*
 * Y
 * |
 * 0 ---- X
 * A    B
 * */
// #define HBOT_AXIS_1
/*
 *          X
 *          |
 * Y ------ 0
 * A    B
 * */
#define HBOT_AXIS_2

/** 模板
#ifdef HBOT_AXIS_1
#elif defined(HBOT_AXIS_2)
#endif // HBOT_AXIS
 * */

#define X_RATIO 1
#define Y_RATIO 1

/// 显示屏 ____________________________________________________________________________________
#define EXAMPLE_PIN_NUM_MISO -1 // 不需要
#define EXAMPLE_PIN_NUM_MOSI 12
#define EXAMPLE_PIN_NUM_SCLK 11
#define EXAMPLE_PIN_NUM_LCD_CS 42
#define EXAMPLE_PIN_NUM_LCD_DC 41
#define EXAMPLE_PIN_NUM_LCD_RST 40
#define EXAMPLE_PIN_NUM_BK_LIGHT 39

/// For SD card ____________________________________________________________________________________
#define SD_CLK_PIN (41)
#define SD_MISO_PIN (42)
#define SD_MOSI_PIN (40)
#define SD_CS_PIN (39)

/// For Motor ____________________________________________________________________________________
#define EN_PIN (48)
#define STEP_PIN (7)
#define DIR_PIN (15)

#define EN_PIN2 (48)
#define STEP_PIN2 (19)
#define DIR_PIN2 (20)

// 电磁铁引脚定义
#define MEAG1 (4)
#define MEAG2 (5)
#define MEAG3 (6)
#define MEAG4 (16)
// #define MEAG5   (10) //Chessbot2.0
#define MEAG5 (47) // Chessbot2.1
/// BUZZER ____________________________________________________________________________________
#define BUZZER_PIN 21 // Chessbot2.1

/// 编码器引脚定义
#define ENCODER_A_PIN 35
#define ENCODER_B_PIN 36
#define ENCODER_KEY_PIN 37

/// Endstop ____________________________________________________________________________________
#define endstop_X 2
#define endstop_Y 14 // 18
/// For WS2812 ____________________________________________________________________________________
#define PIN 9
#define NUM_LEDS 1
/// BUTTON -------------------------------------------------------------------------------------
#define BUTTON_PIN 17

/// HOME步数
#define X_RESET_STEPS 0
#define Y_RESET_STEPS 0

#define hall1 -1
#define hall2 -1

extern int batteryLevel_g;        // 电量
extern int beepLevel_g;           // beep音量
extern int speed_g;               // 运动速度
extern bool speaker_g;            // 语音控制开关
extern int errorCode;             // 错误代码
extern int encoderValue;          // 编码器值
extern bool encoderButton;        // 编码器按钮
extern bool id_status;            // id板状态
extern bool calibration_x_g;      // x校准状态
extern bool calibration_y_g;      // y校准状态
extern String firmware_version_g; // 固件版本
extern String firmware_name_g;    // 固件名字
extern bool firmware_status;      // 是否要更新
extern int level_difficulty_g;    // 难度等级
extern bool button_state;
extern bool button_state2;
extern bool wifi_status_g;       // wifi状态
extern bool deviceConnected_g;   // 蓝牙状态
extern bool serial_enable_g;     // 串口使能
extern bool firmware_new_status; // 是否有新固件
extern bool isSyncing;           // 是否正在同步
extern int mode_g;               // 模式
extern bool Charging_status;     // 充电状态
extern String sn_g;
extern String ip_g;
extern String wifi_name_g;
extern float hall_sensitivity_val;
extern int print_key;
extern void updateVoiceStatus(bool enabled);
extern void sendFrameToVoiceModule(uint8_t command);
void motor_speed_set(String speed);
void speaker_set(String value);
void beep_set(int level);
int get_current_speed();
void speed_set(int speed);
void loadPreferences();
void savePreferences();
void save_level();
void savelocation(float x, float y);
#endif // CHESSBOTBOARD_CONFIG_H
